<style lang="scss" scoped>
.agent {
  height: 100%;
  background-color: #f0f0f2;

  .agent-list {
    padding-top: 0.44rem;
  }
}
</style>

<template>
    <div class="agent">
        <div class="topbar">
            <span class="leftbtn" @click="goback"><Icon type="ios-arrow-back"></Icon></span>
            <span class="centertitle">经销商列表</span>
            <span class="rightbtn" @click="addAgent">新增</span>    
        </div>     
        <div class="agent-list">
            <el-table :data="agentList" @row-click="dblclick" >
              <el-table-column  label="经销商" prop="agentName"></el-table-column>
              <el-table-column label="联系方式" prop="phone"></el-table-column>
              <el-table-column label="地址" prop="addr"></el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
import { sampleData } from "api/index.js";
export default {
  data() {
    return {
      agentList: []
    };
  },
  methods: {
    goback() {
      this.$router.push('/index')
    },
    addAgent(){
        this.$router.push('/agent');
        this.$store.state.agentOperation="add";
    },
    dblclick(row){
        this.$store.state.agentOperation="edit";
         this.$router.push({path:'agent',query:{agentId:row.id}});
    },
    getAgentListByUserId(){
      let obj={}
      sampleData.getAgentListByUserId(obj).then(res=>{
        if (res.code == 0 || res.code == 200) {
          this.agentList=res.list;
        }else{
          this.$Message.error(res.msg)
        }
        
      }).catch(error=>{
        this.$Message.error(error)
      })
    }
  },
  mounted() {
    this.getAgentListByUserId();
  },
};
</script>


